'use strict';

const { Service } = require('egg');
class ApiService extends Service {
  // 添加api
  async createApi (info) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.insert('api', info); // 给list表新增一条数据
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  // 编辑api
  async editApi (id, api, url, method, instruction) {
    const { ctx, app } = this;
    try {
      const result = await app.mysql.update('api', { api, url, method, instruction }, {
        where: {
          id
        }
      });
      return result;
    } catch (error) {
      console.log(error);
      return null;
    }
  }
  async deleteApi (id) {
    const { app } = this;
    try {
      const result = app.mysql.delete('api', {
        id,
      });
    } catch (error) {
      return null;
    }
  }
}
module.exports = ApiService;
